<?php

set_time_limit(0);

define('ROOT_PATH', str_replace('Cli/'.basename(__FILE__), '', str_replace('\\', '/', __FILE__)));

require_once(ROOT_PATH."Cls/const.php");
require_once(ROOT_PATH."Cls/common.php");
require_once(ROOT_PATH."Cls/db.php");
require_once(ROOT_PATH."Cls/Snoopy.class.php");
require_once(ROOT_PATH."Cls/lib_jd.php");
require_once(ROOT_PATH."Cls/yunip.class.php");
require_once(ROOT_PATH."Cls/curl.php");

/*收货状态：0未收货，1待收货(收货中)，2已收货 ，-1收货失败*/

$receive_un_receive = 0;
$receive_receiveing = 1;
$receive_received   = 2;
$receive_fail       = -1;

//请求
$cCurl = new Curl();

//订单号
$order_id = intval(def_post('order_id',0));

if($order_id > 0){

    $db = new DB();

    //读取需要抓取的列表
    $order = get_order_info($order_id);

    if($order){

        //设置收货中
        $receiveing = order_receive_status_update($order_id,$receive_receiveing);

        //收货确认
        $receive_result = receive_jd_order($order,$msg_ip);

        if($receive_result){

            //设置收货成功
            order_receive_status_update($order_id,$receive_received);

            json_success($msg_ip);
        }else{

            //设置收货失败
            order_receive_status_update($order_id,$receive_fail);

            json_error($msg_ip);
        }
    }else{
        json_error('未获取到该订单:'.$order_id);
    }
}